<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@page import="org.jeecgframework.web.util.StaticValue" %>
<%@include file="/context/mytags.jsp" %>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div class="easyui-layout" fit="true">
    <div region="center" style="padding:1px;">
        <t:datagrid name="argEngineerList" checkbox="true" title="区域工程师任务"
                    actionUrl="cbsServiceAssignListController.do?facilitators" fitColumns="false" idField="id" pageList="[20,100,200]"
                    queryMode="group" onLoadSuccess="changetxt">
            <t:dgCol title="主键" field="id" hidden="true" queryMode="single" width="120"></t:dgCol>
            <t:dgCol title="设备SN" field="sn" queryMode="single" width="120" query="true"></t:dgCol>
            <t:dgCol title="服务单号" field="code" queryMode="single" width="120" query="true"
                     url="cbsServiceAssignListController.do?detailsOfDistrictService&id={id}"
                     funname="CbsserviceArgEngDetials"></t:dgCol>
            <t:dgCol title="工程师" field="assignType" queryMode="single" width="100" query="true"></t:dgCol>
            <t:dgCol title="服务商处理时长" field="dealWithTiem" queryMode="single" width="105"></t:dgCol>
            <t:dgCol title="服务类型" field="serviceType" queryMode="single" width="85" query="true"></t:dgCol>
            <t:dgCol title="级别" field="level" queryMode="single" width="40"
                     dictionary="<%=StaticValue.serviceLevel%>"></t:dgCol>
            <t:dgCol title="处理进度" field="speedStatus" queryMode="single" width="120"
                     dictionary="<%=StaticValue.Third_Party_Processing_Progress %>"></t:dgCol>
            <t:dgCol title="服务商处理进度" field="speedstatus1" hidden="true" query="true"></t:dgCol>
            <t:dgCol title="服务商处理进度" field="speedstatus2" hidden="true" query="true"></t:dgCol>
            <t:dgCol title="服务单类型" field="sourceType" queryMode="single" width="120"
                     dictionary="<%=StaticValue.Source_Type%>" hidden="true"></t:dgCol>
            <t:dgCol title="影院名称" field="intheaterName" queryMode="single" width="180" query="true"></t:dgCol>
            <t:dgCol title="院线" field="typename" queryMode="single" width="60" query="true"></t:dgCol>
            <t:dgCol title="省" field="provinces" queryMode="single" width="120" query="true"></t:dgCol>
            <t:dgCol title="市" field="city" queryMode="single" width="120"></t:dgCol>
            <t:dgCol title="联系人姓名" field="contactsName" queryMode="single" width="80"></t:dgCol>
            <t:dgCol title="联系人手机" field="phone" queryMode="single" width="100" query="true"></t:dgCol>
            <t:dgCol title="派单时间" field="assignTime" formatter="yyyy-MM-dd hh:mm" queryMode="group" width="120"
                     query="true"></t:dgCol>
            <t:dgCol title="预约上门时间" field="orderTime" formatter="yyyy-MM-dd " queryMode="group"
                     width="110"></t:dgCol>
           <t:dgCol title="现场完工时间" field="finishTime" formatter="yyyy-MM-dd hh:mm" queryMode="group" width="120"
                     query="true"></t:dgCol>
            <t:dgCol title="系统完工时间" field="closeTime" formatter="yyyy-MM-dd hh:mm" queryMode="group" width="120"
                     query="true"></t:dgCol>
            <t:dgCol title="备件申请" field="apply" queryMode="single" width="70" query="true"
                     dictionary="<%=StaticValue.DIC_TRUE_OR_FALSE_NUM %>"></t:dgCol>
            <t:dgCol title="备件预计到货时间" field="expecttime" queryMode="single" width="125"></t:dgCol>
            <t:dgCol title="SO号" field="so" queryMode="single" width="80" query="true"></t:dgCol>
            <t:dgToolBar title="派单" icon="icon-add" funname="findArgEngineerPeople"></t:dgToolBar>
            <%--<t:dgToolBar title="拒绝" icon="icon-edit" funname="refuseArgEngineerPeople()"></t:dgToolBar>--%>
            <t:dgToolBar title="导出" icon="icon-putout" funname="ExportXls"></t:dgToolBar>
        </t:datagrid>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        //给时间控件加上样式
        $("#argEngineerListtb").find("input[name='assignTime_begin']").attr("class", "Wdate").attr("style", "height:20px;width:90px;").click(function () {
            WdatePicker({dateFmt: 'yyyy-MM-dd'});
        });
        $("#argEngineerListtb").find("input[name='assignTime_end']").attr("class", "Wdate").attr("style", "height:20px;width:90px;").click(function () {
            WdatePicker({dateFmt: 'yyyy-MM-dd'});
        });
        $("#argEngineerListtb").find("input[name='closeTime_begin']").attr("class", "Wdate").attr("style", "height:20px;width:90px;").click(function () {
            WdatePicker({dateFmt: 'yyyy-MM-dd'});
        });
        $("#argEngineerListtb").find("input[name='closeTime_end']").attr("class", "Wdate").attr("style", "height:20px;width:90px;").click(function () {
            WdatePicker({dateFmt: 'yyyy-MM-dd'});
        });
    });

    $(function () {
        territoryLink('argEngineerList', 'provinces', 1);
        territoryLinks('argEngineerList', 'serviceType', 1);

        //服务商处理进度
        $("div[name='searchColums'] span:nth-child(5)").hide();
        $("[name='speedstatus2']").combobox({
            data: [{
                "id": 0,
                "text": "HD待分派"
            }, {
                "id": 1,
                "text": "第三方已拒绝"
            }, {
                "id": 2,
                "text": "已分派第三方",
            }, {
                "id": 3,
                "text": "第三方已分配"
            }, {
                "id": 4,
                "text": "区域工程师已分配"
            }, {
                "id": 5,
                "text": "工程师已接受"
            }, {
                "id": 6,
                "text": "工程师实施中"
            }, {
                "id": 7,
                "text": "服务已完成"
            }],
            valueField: 'id',
            textField: 'text',
            editable: false,
            multiple: true,
            onSelect: function (row) { //选中一个选项时调用
                //获取选中的值的values
                $("[name='speedstatus1']").val($(this).combobox('getValues'));
            },
            onUnselect: function (row) {//不选中一个选项时调用
                //获取选中的值的values
                $("[name='speedstatus1']").val($(this).combobox('getValues'));
            }
        });
    });

    function searchReset() {
        addOneTab("区域工程师任务", "cbsServiceAssignListController.do?argengineerlist", "");
    }

    //导出
    function ExportXls() {
        var currPageRows = $("#argEngineerList").datagrid("getRows");
        var idsData = [];
        $(currPageRows).each(function (i, rowData) {
            idsData.push(rowData.id);
        });
        if (idsData.length > 0) {
            myDownload("cbsServiceController.do?exportInspectionAssignList", "planIds=" + idsData.join(","));
        } else {
            tip("当前页面没有数据可以导出");
        }
    }

    //工程师查询条件
    function findArgEngineerPeople() {
        var datas = $("#argEngineerList").datagrid("getSelections");
        if (datas.length == 0) {
            tip("请选择要分派的服务单!");
            return;
        }
        var planIdArr = [];
        $.each(datas, function (i, item) {
            planIdArr.push(item.id);
        });
        var planIds = planIdArr.join(",");
        if (judge(planIds)) {
            $.ajax({
                url: "cbsServiceAssignListController.do?inspectArgEng",
                data: {
                    "planIds": planIds
                },
                cache: false,
                dataType: 'json',
                type: 'POST',
                async: true,
                beforeSend: function () {
                    lockmask(true);
                },
                success: function (data) {
                    if (data.success) {
                        createwindow("分派", "cbsServiceAssignListController.do?findArgEngineerPeopleList&planIds=" + planIds, 600, 400);
                    } else {
                        tip(data.msg);
                    }
                },
                complete: function () {
                    lockmask(false);
                }
            });
        } else {
            tip("操作人与派单人不符，请刷新系统！");
        }
    }

    //拒绝
    function refuseArgEngineerPeople() {
        var datas = $("#argEngineerList").datagrid("getSelections");
        if (datas.length == 0) {
            tip("请选择要分派的服务单!");
            return;
        }
        var planIdArr = [];
        $.each(datas, function (i, item) {
            planIdArr.push(item.id);
        });
        var planIds = planIdArr.join(",");
        if (judge(planIds)) {
            createwindow("拒绝", "cbsServiceAssignListController.do?refuseArgEngineerPeopleList&planIds=" + planIds, 1200, 400);
        } else {
            tip("操作人与派单人不符，请刷新系统！");
        }
    }

    /**
     * 区域工程师服务单详情
     * @param filedName
     * @param url
     * @constructor
     */
    function CbsserviceArgEngDetials(filedName, url) {
        addOneTab("服务订单详情", url);
    }


    /*判断派单人是否是当前登录人*/
    function judge(planIds) {
        var flag = false;
        $.ajax({
            url: "cbsServiceController.do?judgePeople",
            data: {
                "cbsId": planIds,
                "type": "2"
            },
            async: false,
            cache: false,
            dataType: 'json',
            type: 'POST',
            error: function () {// 请求失败处理函数
            },
            success: function (data) {
                if (data.success) {
                    flag = true;
                }
            }
        });

        return flag;
    }
    
    /*处理文字*/
    function changetxt() {
        var trs = $("#argEngineerList").prev().find('div.datagrid-body').find('tr');
        for (var i = 0; i < trs.length; i++) {
        	if (trs[i].cells[4].firstChild.innerHTML == 'null') {
        		trs[i].cells[4].firstChild.innerHTML = '';
        	} else{
              trs[i].cells[4].firstChild.innerHTML = trs[i].cells[4].firstChild.innerHTML + '小时';
        	}
        }
     }
</script>